package bid.yanhj.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import bid.yanhj.springboot.filter.SecondFilter;
import bid.yanhj.springboot.listener.SecondListener;
import bid.yanhj.springboot.servlet.SecondServlet;

/**
 * 启动器启动的时候扫描servlet组件 第二中方法
 *
 */
@SpringBootApplication
public class springbootApplication2 {
    public static void main(String[] args) {
        // 启动应用
        SpringApplication.run(springbootApplication2.class, args);
    }

    /**
     * 注册Servlet
     * 
     * @return
     */
    @Bean
    public ServletRegistrationBean getServletRegistrationBean() {
        ServletRegistrationBean bean = new ServletRegistrationBean(new SecondServlet());
        bean.addUrlMappings("/second");
        return bean;
    }

    /**
     * 注册Filter
     * 
     * @return
     */
    @Bean
    public FilterRegistrationBean getFilterRegistrationBean() {
        FilterRegistrationBean bean = new FilterRegistrationBean(new SecondFilter());
        bean.addUrlPatterns("/second");
        return bean;
    }

    /**
     * 注册监听器
     * @return
     */
    @Bean
    public ServletListenerRegistrationBean<SecondListener> getServletListenerRegistrationBean() {
        ServletListenerRegistrationBean<SecondListener> bean = new ServletListenerRegistrationBean<SecondListener>(
                new SecondListener());
        return bean;
    }
}
